package com.idea.cery.springboot1.base.datasource;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;


import javax.sql.DataSource;

/**
 * @Author:cery
 * @Version 1.0
 * @Date:2020/4/10
 */
@Configuration
public class JdbcDataSource {

    /**
     * 创建db1数据库连接
     *
     * @return
     */
    @Primary
    @Bean(name = "db1DataSource")
    @ConfigurationProperties(prefix = "spring.datasource.db1")
    public DataSource Db1DataSource() {
        return DataSourceBuilder.create().build();
    }

    /**
     * 数据库操作
     *
     * @param dataSource
     * @return
     */
    @Bean(name = "db1JdbcTemplate")
    public JdbcTemplate db1JdbcTemplate(@Qualifier("db1DataSource") DataSource dataSource) {

        return new JdbcTemplate(dataSource);
    }
}
